﻿
Imports System.Net
Imports System.IO
Imports System.IO.Path
Imports System.Data
Imports VSModel
Imports Cls_Common

Partial Class Control_CertifiedHousehold_Detail
    Inherits System.Web.UI.UserControl
#Region "Sub and Function "
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then

            'Dim script As ScriptManager = ScriptManager.GetCurrent(Me.Page)
            'If Not script Is Nothing AndAlso script.IsInAsyncPostBack Then
            '    ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType, "duyjs", "ajaxJquery()", True)
            'Else
            '    Me.Page.ClientScript.RegisterStartupScript(Me.Page.GetType(), "duyjs", String.Concat("Sys.Application.add_load(function(){", "ajaxJquery()", "});"), True)
            'End If

            If Not Request.QueryString("Certifiedid").ToString.Equals("0") Then
                hidID.Value = Request.QueryString("Certifiedid")
                ShowData()
            End If
        End If
    End Sub
    Protected Sub ShowData()

        Using _data As New VSEntities

            'load data CertifiedHousehold
            Dim p = (From q In _data.CertifiedHouseholds Where q.CertifiedID = hidID.Value Select q).FirstOrDefault

            Dim __curHuyenId As Integer = Session("HuyenId")
            'co quan cap huyen
            Dim _CoQuan = (From q In _data.Provinces Where q.Id = __curHuyenId Select q).FirstOrDefault
            If Not _CoQuan Is Nothing Then
                lblTenCoQuanCapHuyen.Text = "ỦY BAN NHÂN DÂN " & _CoQuan.Title.ToString
            End If

            'ngay tao
            If Not p.Created Is Nothing Then
                Dim _ngaytao As DateTime = CType(p.Created, DateTime)
                lblNgayTao.Text = _CoQuan.Title.ToString & ", ngày " & _ngaytao.Day & ", tháng " & _ngaytao.Month & ", năm " & _ngaytao.Year
            End If
            'thong tin ca nhan
            lblTenNguoiDangky.Text = IIf(IsNothing(p.Ow_Name) = True, "", p.Ow_Name)
            'giới tính
            Dim _Idgt As Integer = IIf(IsNothing(p.Ow_Sex) = True, "", p.Ow_Sex)
            If _Idgt = 1 Then
                lblGioiTinh.Text = "Nam"
            ElseIf _Idgt = 0 Then
                lblGioiTinh.Text = "Nữ"
            End If
            lblNgaySinh.Text = IIf(IsNothing(p.Ow_BirthDate) = True, "", p.Ow_BirthDate)
            lblSoCMND.Text = IIf(IsNothing(p.Ow_CardID) = True, "", p.Ow_CardID)
            If Not p.Ow_CardDate Is Nothing AndAlso p.Ow_CardDate <> #1/1/1900# Then
                lblNgayCapCMND.Text = CType(p.Ow_CardDate, DateTime).ToString("dd/MM/yyyy")
            End If
            lblNoiCap.Text = IIf(IsNothing(p.Ow_Provider_ID) = True, "", p.Ow_Provider_ID)
            'giấy tờ khác
            Dim _IDCertifiedPaperDict As String = IIf(IsNothing(p.Ow_Doc_ID) = True, "", p.Ow_Doc_ID)
            If _IDCertifiedPaperDict <> "" Then
                lblGCTKhac.Text = (From q In _data.CertifiedPaperDicts Where q.Id = _IDCertifiedPaperDict Select q.Name).FirstOrDefault
            End If

            If Not p.Ow_DocDate Is Nothing AndAlso p.Ow_DocDate <> #1/1/1900# Then
                lblNgayCapGCTCN.Text = CType(p.Ow_DocDate, DateTime).ToString("dd/MM/yyyy")
            End If
            lblSoCTCN.Text = IIf(IsNothing(p.Ow_DocCode) = True, "", p.Ow_DocCode)


            lblVon.Text = IIf(IsNothing(p.Biz_WordsMoney) = True, "", p.Biz_WordsMoney)


            'Thông tin hộ kinh doanh: 
            lblTenHoKinhDoanh.Text = IIf(IsNothing(p.Biz_VietName) = True, "", p.Biz_VietName)
            'lbl.Text = IIf(IsNothing(p.Biz_HeadOffice) = True, "", p.Biz_HeadOffice)
            lblDienThoaiDD.Text = IIf(IsNothing(p.Ow_Tel) = True, "", p.Ow_Tel)
            lblFaxDD.Text = IIf(IsNothing(p.Ow_Fax) = True, "", p.Ow_Fax)
            lblMailDD.Text = IIf(IsNothing(p.Ow_Email) = True, "", p.Ow_Email)
            lblWebsiteDD.Text = IIf(IsNothing(p.Ow_WebSite) = True, "", p.Ow_WebSite)

            'Địa chỉ phường xa huyên
            'thuong trú
            Dim _jth = (From q In _data.CertifiedHouseholdAddresses Where q.CertifiedID = hidID.Value And q.TypeId = LoaiDiaChi.ThuongTru Select q).FirstOrDefault
            If Not _jth Is Nothing Then
                lblSoNhaThuongTru.Text = _jth.Adress
                Dim _TinhTT = (From q In _data.Provinces Where q.Id = _jth.TinhId Select q).FirstOrDefault
                If Not _TinhTT Is Nothing Then
                    lblTinhThuongTru.Text = _TinhTT.Title
                End If
                Dim _HuyenTT = (From q In _data.Provinces Where q.Id = _jth.TinhId Select q).FirstOrDefault
                If Not _HuyenTT Is Nothing Then
                    lblHuyenThuongTru.Text = _HuyenTT.Title
                End If
                Dim _XaTT = (From q In _data.Provinces Where q.Id = _jth.TinhId Select q).FirstOrDefault
                If Not _XaTT Is Nothing Then
                    lblXaThuongTru.Text = _XaTT.Title
                End If
            End If
            'tam trú
            Dim _jtr = (From q In _data.CertifiedHouseholdAddresses Where q.CertifiedID = hidID.Value And q.TypeId = LoaiDiaChi.TamTru Select q).FirstOrDefault
            If Not _jtr Is Nothing Then
                lblSoNhaHienTai.Text = _jtr.Adress
                Dim _TinhHT = (From q In _data.Provinces Where q.Id = _jtr.TinhId Select q).FirstOrDefault
                If Not _TinhHT Is Nothing Then
                    lblTinhHienTai.Text = _TinhHT.Title
                End If
                Dim _HuyenHT = (From q In _data.Provinces Where q.Id = _jtr.TinhId Select q).FirstOrDefault
                If Not _HuyenHT Is Nothing Then
                    lblHuyenHienTai.Text = _HuyenHT.Title
                End If
                Dim _XaHT = (From q In _data.Provinces Where q.Id = _jtr.TinhId Select q).FirstOrDefault
                If Not _XaHT Is Nothing Then
                    lblXaHienTai.Text = _XaHT.Title
                End If
            End If
            'đia điểm kinh doanh
            Dim _jdd = (From q In _data.CertifiedHouseholdAddresses Where q.CertifiedID = hidID.Value And q.TypeId = LoaiDiaChi.DiaDiemKinhDoanh Select q).FirstOrDefault
            If Not _jdd Is Nothing Then
                lblSoNhaDD.Text = _jdd.Adress
                lblSoNhaHienTai.Text = _jtr.Adress
                Dim _TinhDD = (From q In _data.Provinces Where q.Id = _jdd.TinhId Select q).FirstOrDefault
                If Not _TinhDD Is Nothing Then
                    lblTinhDD.Text = _TinhDD.Title
                End If
                Dim _HuyenDD = (From q In _data.Provinces Where q.Id = _jdd.TinhId Select q).FirstOrDefault
                If Not _HuyenDD Is Nothing Then
                    lblHuyenDD.Text = _HuyenDD.Title
                End If
                Dim _XaDD = (From q In _data.Provinces Where q.Id = _jdd.TinhId Select q).FirstOrDefault
                If Not _XaDD Is Nothing Then
                    lblXaDD.Text = _XaDD.Title
                End If
            End If
            'load ngành nghề kinh doanh
            Dim IdCertified As Integer = hidID.Value
            Dim NganhNghe = (From q In _data.CertifiedHouseholdNganhNghes Where q.CertifiedID = IdCertified Order By q.Id Select q.DanhMucNganhNgheID).ToArray
            Dim TenNganhNghe = (From q In _data.DanhMucNganhNghes Where NganhNghe.Contains(q.Id) Order By q.Name Select q.Name).ToList
            Dim listNganhNghe As String = ""
            For Each item In TenNganhNghe
                listNganhNghe += " - " & item & "<br/>"
            Next
            lblNganhNgheKinhDoanh.Text = listNganhNghe

            'giay to kem theo
            Dim IdThanhPhanHoSo As Integer = hidID.Value
            Dim ThanhPhanHoSo = (From q In _data.CertifiedHouseholdThanhPhanHoSoes Where q.CertifiedID = IdThanhPhanHoSo Order By q.Id Select q.ThanhPhanHoSoId).ToArray
            Dim TenThanhPhanHoSo = (From q In _data.ThanhPhanHoSoes Where ThanhPhanHoSo.Contains(q.Id) Order By q.TenHoSo Select q.TenHoSo).ToList
            Dim listThanhPhanHoSo As String = ""
            For Each item In TenThanhPhanHoSo
                listThanhPhanHoSo += " - " & item & "<br/>"
            Next
            lblGiayToKemTheo.Text = listThanhPhanHoSo
        End Using
        

    End Sub
#End Region
End Class
